package com.you.modules.activemq.controller;

import com.you.common.util.ResponseUtil;
import com.you.modules.activemq.bean.IActiveMqProducer;
import com.you.modules.activemq.constant.MqConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/activemq")
public class ActiveMqController {
    private static final Class LOG_TARGET = ActiveMqController.class;

    @Autowired
    @Qualifier("activeMqQueueProducer")
    private IActiveMqProducer activeMqQueueProducer;

    @Autowired
    @Qualifier("activeMqTopicProducer")
    private IActiveMqProducer activeMqTopicProducer;

    @PostMapping("/queue/send")
    @ResponseBody
    public Object sendToQueue(@RequestBody Object message) {
        activeMqQueueProducer.send(MqConstant.Destination.QUEUE_TEST, message);
        return ResponseUtil.success(message);
    }

    @PostMapping("/topic/send")
    @ResponseBody
    public Object sendToTopic(@RequestBody Object message) {
        activeMqTopicProducer.send(MqConstant.Destination.TOPIC_TEST, message);
        return ResponseUtil.success(message);
    }
}
